/* Sentinel - IRC Statistical and Operator Services
** flags.c - Support functions to .flags
**
** Copyright W. Campbell and others.  See README for more details
** Some code Copyright: Jonathan George, Kai Seidler, ircd-hybrid Team,
**                      IRCnet IRCD developers.
**
** $Id: flags.c,v 1.10 2003/04/07 14:32:49 wcampbel Exp $
*/

#include "stats.h"
#include "struct.h"
#include "proto.h"
#include "token.h"
#include "flags.h"

struct Token flags_table[] =
  {
    { "AUTH", CF_AUTH },
    { "NOTICES", CF_NOTICES },
    { "JUPE", CF_JUPE },
    { "OPER", CF_OPER },
    { "COMMANDS", CF_COMMANDS },
    { "USER", CF_USER },
    { "KILL", CF_KILL },
    { "MISC", CF_MISC },
    { "SERVICES", CF_SERVICES },
    { "TLD", CF_TLD },
    { "CHAT", CF_CHAT },
    { "ALL", CF_ALL },
    { NULL, TOKEN_ERROR }
  };

struct Token oper_flags[] =
  {
    { "ADMIN", MFLAG_ADMIN },
    { "STATS", MFLAG_STATS },
    { "SPLIT", MFLAG_SPLIT },
    { "JUPE", MFLAG_JUPE },
    { "LIST", MFLAG_LIST },
    { "OP", MFLAG_OP },
    { "TAKEOVER", MFLAG_TAKEOVER },
    { NULL, TOKEN_ERROR }
  };

void send_set_flags(struct Connection *conn)
{
  int i;
  char out[LINE];

  out[0] = '\0';

  for (i = 0; flags_table[i].text != NULL; i++)
  {
    /* Don't display ALL ever */
    if (flags_table[i].value == CF_ALL)
      continue;
    if (conn->flags & flags_table[i].value)
    {
      strlcat(out, " ", LINE);
      strlcat(out, flags_table[i].text, LINE);
    }
  }
  if (out[0] != '\0')
  {
    /* Purposefully leave the extra space */
    sendto_dcc(conn->fd, "Set flags:%s", out);
  }
}

void send_unset_flags(struct Connection *conn)
{
  int i;
  char out[LINE];

  out[0] = '\0';

  for (i = 0; flags_table[i].text != NULL; i++)
  {
    /* Don't display ALL ever */
    if (flags_table[i].value == CF_ALL)
      continue;
    if (!(conn->flags & flags_table[i].value))
    {
      strlcat(out, " ", LINE);
      strlcat(out, flags_table[i].text, LINE);
    }
  }
  if (out[0] != '\0')
  {
    /* Purposefully leave the extra space */
    sendto_dcc(conn->fd, "Unset flags:%s", out);
  }
}

char *show_oper_flags(struct MyUser *myu)
{
  int i;
  static char out[LINE];

  out[0] = '\0';

  for (i = 0; oper_flags[i].text != NULL; i++)
  {
    if (myu->flags & oper_flags[i].value)
    {
      strlcat(out, " ", LINE);
      strlcat(out, oper_flags[i].text, LINE);
    }
  }
  return out;
}
